package com.pignest.hotel.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;

public class TestServlet extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charrset=GBK");
		ResultSet resultSet = null;
		Connection con = null;//JDBC.getConnection();
		PreparedStatement statement;
		try {
			statement = con.prepareStatement("select * from fruitSell ");
			resultSet = statement.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		JRResultSetDataSource result = new JRResultSetDataSource(resultSet);
		JasperReport jasperReport;
		try {
			jasperReport = JasperCompileManager.compileReport(getServletContext()
					.getRealPath("reports/fruitSell.jrxml"));

			JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), result);

			JasperExportManager.exportReportToPdfFile(jasperPrint, "reports/fruitSell1.pdf");
		} catch (JRException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		getServletContext().getRequestDispatcher("/doIndex.jsp").forward(request, response);
	}
}
